package chapter17;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/24 11:17
 */
public class ConcurrentHashMapTest {
    public static void main(String[] args) {
        final ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
        map.put("a", "abstract");
        map.put("b", "bill");
        Thread t1 = new Thread(() -> {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(entry.getKey() + ":" + entry.getValue());
            }

        });
        t1.start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        map.put("c", "camel");

    }
}
